package com.mrobuy.jdvc.dao.impl;

import com.mrobuy.jdvc.dao.VCSkuDao;
import com.mrobuy.jdvc.dao.VCUpdateTokenDao;
import com.mrobuy.jdvc.entity.VCUpdateToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("vcUpdateTokenDao")
public class VCUpdateTokenDaoImpl extends CommonDaoImpl implements VCUpdateTokenDao {

    private static Logger LOG = LoggerFactory.getLogger(VCSkuDao.class);

    @Override
    public VCUpdateToken load() {

        StringBuilder sql = new StringBuilder();
        sql.append("select * from VC_UPDATETOKEN ");
        try {
            List<VCUpdateToken> list = getJdbcTemplate().query(sql.toString(), new BeanPropertyRowMapper(VCUpdateToken.class));
            if ( list!=null && list.size() > 0 ) {
                return list.get(0);
            }
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }

        return null;
    }

    @Override
    public VCUpdateToken load(String vendor) {
        StringBuilder sql = new StringBuilder();
        sql.append("select * from VC_UPDATETOKEN where VENDOR = ? ");
        try {
            List<VCUpdateToken> list = getJdbcTemplate().query(sql.toString(), new Object[]{vendor},new BeanPropertyRowMapper(VCUpdateToken.class));
            if ( list!=null && list.size() > 0 ) {
                return list.get(0);
            }
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }

        return null;
    }

}
